{% extends 'layout_panel.html' %}
{% load static %}

{% block panel_js_files %}
<script src="{% static 'js/sharedkit.js' %}"></script>
{% endblock %}

{% block html_js_code %}
<script>
layui.use(function() {
    var util = layui.util;
    var layer = layui.layer;
    var $ = layui.$;
    var form = layui.form;

    util.event('lay-on', {
        OpenSystemServices: function() {
            var url = $(this).attr('data-href');
            OpenSystemServices(url);
            return false;
         },
        serviceAction: function() {
            var href = $(this).attr('data-href');
            var loadIndex = layer.msg('正在处理...', {icon: 16,shade: 0.6});
            $.ajax({
                url: href,
                type: 'get',
                dataType: 'json',
                success: function(response) {
                    layer.close(loadIndex);
                    layer.alert(response.message, {icon: 1, title:null});
                    setTimeout(function() {
                        location.href = '{% url 'db_mysql:detail' install_info.uuid  %}';
                    }, 2000);
                },
                error: function(xhr, status, error) {
                    layer.alert(xhr.message, {icon: 2, title:null});
                }
            })
        }
    })
})
</script>
{% endblock %}

{% block page_content %}
{% if not install_info %}
    <div class="alert alert-warning">
    没有找到安装信息~
    </div>
{% else %}
<div class="card">
<div class="card-header">
    <div class="card-title">
    </div>
    <div class="card-tools">
<a data-href="{% url 'sharedkit:open_system_services' %}" class="btn btn-outline-info" lay-on="OpenSystemServices">
    <i class="fa-solid fa-gears"></i> 系统服务
</a>
    </div>
</div>
<div class="card-body">
{% if install_info.config_status == 0 %}
<div class="alert alert-danger">此版本没有完成运行配置！</div>
 {% endif %}
{% if install_info.config_status == 2 %}
<div class="alert alert-danger">此版本是导入生成，如果有未配置的内容，请先配置！</div>
{% endif %}
    <dl class="row">
        <dt class="col-sm-2">版本</dt>
        <dd class="col-sm-10">{{ install_info.name }}</dd>
        <dt class="col-sm-2">主机</dt>
        <dd class="col-sm-10">local</dd>
        <dt class="col-sm-2">端口</dt>
        <dd class="col-sm-10">{{ install_info.port|default:"未设置" }}</dd>
        <dt class="col-sm-2">安装路径</dt>
        <dd class="col-sm-10">{{ install_info.install_dir }}</dd>
{% if install_info.config_status == 1 or install_info.config_status == 2%}
        <dt class="col-sm-2">配置文件路径</dt>
        <dd class="col-sm-10">
            {{ install_info.conf_file }}
            <a href="{% url 'db_mysql:edit_config' install_info.uuid %}" class="btn btn-outline-info btn-xs ml-2">
                编辑
            </a>
        </dd>
        <dt class="col-sm-2">数据文件夹路径</dt>
        <dd class="col-sm-10">{{ install_info.data_dir }}</dd>
        <dt class="col-sm-2">root密码状态</dt>
        <dd class="col-sm-10">
            {% if install_info.set_root_password == 0  %}
                <span class="text-danger">未设置密码</span>
                <a href="{% url 'db_mysql:init_root_password' install_info.uuid %}" class="btn btn-primary btn-xs ml-2">
                    设置密码
                </a>
            {% endif %}
            {% if install_info.set_root_password == 1  %}已设置密码 {% endif %}
            {% if install_info.set_root_password == 2  %}未知 {% endif %}
        </dd>
        <dt class="col-sm-2">Windows服务</dt>
            {% if install_info.config_status == 1 and install_info.set_service == 0 %}
                <dd class="col-sm-10">不创建</dd>
            {% elif install_info.config_status == 2 and not install_info.set_service %}
                <dd class="col-sm-10">未知
                   <a href="{% url 'db_mysql:import_service' install_info.uuid %}" class="btn btn-outline-info btn-xs">配置服务</a>
                </dd>
            {% else %}<dd class="col-sm-10">
<span class="text-{{ server_status.color }} text-bold">
    <i class="fa-solid fa-lightbulb"></i>{{ server_status.status_text }}
</span>
{% if server_status.status == 'stopped' or server_status.status == 'paused' %}
    <a data-href="{% url 'db_mysql:server_status' install_info.uuid 'start' %}" class="btn btn-success btn-xs"  lay-on="serviceAction"><i class="fa-solid fa-play"></i>启动</a>
{% endif %}
    <a data-href="{% url 'db_mysql:server_status' install_info.uuid 'restart' %}" class="btn btn-info btn-xs" lay-on="serviceAction"><i class="fa-solid fa-arrows-rotate"></i>重启</a>
{% if server_status.status == 'running' %}
    <a data-href="{% url 'db_mysql:server_status' install_info.uuid 'stop' %}" class="btn btn-danger btn-xs" lay-on="serviceAction"><i class="fa-solid fa-stop"></i>停止</a>
{% endif %}</dd>
        <dt class="col-sm-2">服务名称</dt>
        <dd class="col-sm-10">{{ install_info.service_name }}</dd>
        <dt class="col-sm-2">自启动</dt>
        <dd class="col-sm-10">{% if install_info.service_auto  %}自启动{% else %}手动{% endif %}</dd>
            {% endif %}

    <hr/>

{% endif %}
    </dl>
</div>
<div class="card-footer">
     <a href="{% url 'db_mysql:uninstall' install_info.uuid %}" class="btn btn-secondary float-right"
       onclick="return confirm('确定要卸载吗?\r卸载将一并删除数据库文件和配置文件且无法删除！');">卸载
    </a>
</div>
</div>
{% endif %}
{% endblock %}